#http://stackoverflow.com/questions/1927660/compare-two-images-the-python-linux-way
def compare_file(image1path, image2path):
    import Image
    import math
    import operator
    __docstring__ = "compare two image files"
    h1 = Image.open(image1path).histogram()
    h2 = Image.open(image2path).histogram()
    rms = math.sqrt(reduce(operator.add, map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
    return rms == 0

# compare two image objects
# condition: Image is already imported
def compare_images(image1, image2):
    h1 = image1.histogram()
    h2 = image2.histogram()
    rms = math.sqrt(reduce(operator.add, map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
    return rms == 0

##Usage
##chunk = chunks[i] # list of image_load()-ed images (chunk object)
##chunk.type = get_block_type(chunk)
##block_file.write(chunk.x, chunk.y, chunk.type)



# find the block type from a set of block chunks
# chunk must use image_load for transparency
def get_block_type(chunk):
    histogram = chunk.histogram()
    for block in block_images:
        if compare_images(chunk, block):
            return block.name
    return "block not found"
        
